package com.yuyuan.common.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class WechatUtil {
    public static JSONObject getSessionKeyOrOpenId(String code) {
        String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
        Map<String, String> requestUrlParam = new HashMap<>();
        requestUrlParam.put("appid", WXConstant.APPID);
        requestUrlParam.put("secret", WXConstant.SECRET);
        requestUrlParam.put("js_code", code);
        requestUrlParam.put("grant_type", "authorization_code");

        // 发送post请求读取调用微信接口获取openid用户唯一标识
        String response = HttpClientUtil.doPost(requestUrl, requestUrlParam);
        return JSONObject.parseObject(response);
    }
}
